﻿using System;
using Echo.Context.UltiProNet.Contexts;
using Echo.Core.TestAbstraction.WebUITest.MbUnit;
using Echo.Models.UltiProNet;
using Echo.Models.UltimateSoftware.WebUITest.MbUnit;
using MbUnit.Framework;
using Echo.Core.Common;

////*************************************************************************************************************************************
////Created by: Jannette Hamilton
////Date created: November 6, 2013
////Modified by: 
////Date modified: 
////Reason: CONVERTED FROM SWAT: SuiteCompliance.SuiteDotNet.SuiteCompanyTaxSetup.SuiteGuiTests.TestBusRuleTaxCodes.TestBusRuleTaxCodesDetailPageLoad &
////Reason: CONVERTED FROM SWAT: SuiteCompliance.SuiteDotNet.SuiteCompanyTaxSetup.SuiteGuiTests.TestBusRuleTaxCodes.TestBusRuleTaxCodesSummaryPageGUI
////*************************************************************************************************************************************

namespace Echo.Automation.Compliance.BusinessRules.Taxes
{
    [TestFixture]

    [Author("Jannette Hamilton", "Jannette_Hamilton@ultimatesoftware.com")]
    [Category("<Business Rules>")]
    [Header("Config")]
    [Config(".NET")]
    //[Config("IEOnly")]
    //[Config("ChromeOnly")]
    //[Config("FFOnly")]

    public class TaxCodeSummaryAndDetailPages : MbUnitAutomatedTest
    {
        UltiPro UltiPro;
        UltiProDatabaseContext Database;

        [FixtureSetUp]
        public void FixtureSetUp()
        {
            UltiPro = Launch<UltiPro>();
            Database = Init<UltiProDatabaseContext>();
            Database.Company = ConfigDatabase("UltiPro_CALENDAR");
            Database.Company.AddRollBack("RbsBusRuleRole", "rbrBusinessRule in ('TAXCODE')");
            Database.Company.AddRollBack("TaxCode", "ctcCoid = 'BVEBW'");
            UltiPro.Pages.Login.LoginAs("MerrillG", "password", Config.LanguageCode);
            UltiPro.Pages.CompanySelector.ChooseMasterCompany("CALEN");
            UltiPro.Pages.CompanySelector.ChooseComponentCompany("C0014");
        }

        [FixtureTearDown]
        public void FixtureTearDown()
        {
            //Database.Company.RollBackDatabase(); // dbo.TaxCode' is not updatable because the modification affects multiple base tables
            UltiPro.Browser.Quit();
        }

        [SetUp]
        public void SetUp()
        {
            UltiPro.Macros.Navigate.ToBusinessRule("Taxes");
        }

        [TearDown]
        public void TearDown()
        {
        }

        #region Helper Functions
        public void SelectTaxCode(string sTaxCode)
        {
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.CodeFilter, FilterType.Is, sTaxCode);
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, sTaxCode).Click(column => column.Code);
        }
        #endregion

        #region DETAIL PAGE
        [Test(Order = 1)]
        public void VerifyNoSpecialCharInEmployerIdNumber()
        {
            //VERIFY THAT EMPLOYER ID FIELD DOES NOT ACCEPT SPECIAL CHARACTERS
            SelectTaxCode("FLSUIER");
            UltiPro.Pages.TaxCodeContributionRate.Is(header => header.PageHeaderLabel, "innerHTML", UltiPro.Localization.Strings.View_slash_Change_Taxes.ToString());
            UltiPro.Pages.TaxCodeContributionRate.Set(textBox => textBox.EmployerIdNumberTextBox, "123.-456789");
            UltiPro.Pages.TaxCodeContributionRate.ButtonBar.Click(button => button.Reset);
            UltiPro.Pages.TaxCodeContributionRate.Set(textBox => textBox.EmployerIdNumberTextBox, "");
            UltiPro.Pages.TaxCodeContributionRate.ButtonBar.Click(button => button.Cancel);
            UltiPro.Alert.Accept();
        }

        [Test(Order = 2)]
        public void VerifyPrintWorks()
        {
            // VERIFY THAT ER ID FIELD IS BLANK
            SelectTaxCode("FLSUIER");
            UltiPro.Pages.TaxCodeContributionRate.Is(header => header.PageHeaderLabel, "innerHTML", UltiPro.Localization.Strings.View_slash_Change_Taxes.ToString());
            UltiPro.Pages.TaxCodeContributionRate.ButtonBar.Click(button => button.Print);
            UltiPro.Browser.SwitchToWindow("Print");
            UltiPro.Browser.Close();
            UltiPro.Browser.SwitchToMainWindow();
        }

         [Test(Order = 3)]
        public void VerifyHelpWorks()
        {
            // VERIFY THAT ER ID FIEL IS BLANK
            SelectTaxCode("FLSUIER");
            UltiPro.Pages.TaxCodeContributionRate.Is(header => header.PageHeaderLabel, "innerHTML", UltiPro.Localization.Strings.View_slash_Change_Taxes.ToString());
            UltiPro.Pages.TaxCodeContributionRate.ButtonBar.Click(button => button.Help);
            UltiPro.Browser.SwitchToWindow("Help");
            UltiPro.Browser.Close();
            UltiPro.Browser.SwitchToMainWindow();
        }
        #endregion DETAIL PAGE

       #region SUMMARY PAGE
        [Test(Order = 4)]
        public void VerifySummaryPageWYWCER_Chequemates4()
        {
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.CodeFilter, FilterType.Is, "WYWCER");
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", grid => grid.Description, "Wyoming Workers Comp ER").RowExists();
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", column => column.Company, "Chequemates US 4").RowExists();
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", grid => grid.State, "Wyoming", grid => grid.Type, "LIT").RowExists();
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", grid => grid.IsEmployerTax, "Y", grid => grid.EmployerIDNumber, "65194-4").RowExists();
        }

        [Test(Order = 5)]
        public void VerifySummaryPageWYWCER_HUCO3()
        {
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.CodeFilter, FilterType.Is, "WYWCER");
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", column => column.Description, "Wyoming Workers Comp ER").RowExists();
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", column => column.Company, "HUCO3-CalenHR - US Comp 3").RowExists();
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", grid => grid.State, "Wyoming", grid => grid.Type, "LIT").RowExists();
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", grid => grid.IsEmployerTax, "Y", grid => grid.EmployerIDNumber, "").RowExists();
        }

        [Test(Order = 6)]
        public void VerifySummaryPageWYWCER_CO014()
        {
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.CodeFilter, FilterType.Is, "WYWCER");
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", column => column.Description, "Wyoming Workers Comp ER").RowExists();
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", column => column.Company, "Web Payroll Company").RowExists();
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", grid => grid.State, "Wyoming", grid => grid.Type, "LIT").RowExists();
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Code, "WYWCER", grid => grid.IsEmployerTax, "Y", grid => grid.EmployerIDNumber, "").RowExists();
        }

        [Test(Order = 7)]
        public void VerifyDescriptionSort()
        {
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.DescriptionFilter, FilterType.StartsWith, "ABBOTT");
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Description, "ABBOTTSTOWN", column => column.Company, "HUCO3-CalenHR - US Comp 3").RowExists();
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Description, "ABBOTTSTOWN", column => column.Company, "HUCO1-CalenHR - US Comp 1").RowExists();
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Description, "ABBOTTSTOWN", column => column.Company, "Code Filter Company - USA Automation").RowExists();
        }

        [Test(Order = 8)]
        public void VerifyCompanyAscendingSort()
        {
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.CompanyFilter, FilterType.Is, "O1J9M");
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Description, "Auburn", column => column.State, "Alabama").RowExists();
        }

        [Test(Order = 9)]
        public void VerifyCompanyDescendingSort()
        {
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.CompanyFilter, FilterType.Is, "XB3CV");
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Description, "AK State Income Tax", column => column.State, "Alaska").RowExists();
        }
        
       [Test(Order = 10)]
        public void VerifyStateAscendingSort()
        {
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.StateFilter, FilterType.Is, "AL");
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Description, "Auburn", column => column.State, "Alabama").RowExists();
        }

       [Test(Order = 11)]
       public void VerifyStateDesscendingSort()
       {
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.StateFilter, FilterType.Is, "WY");
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(grid => grid.Description, "WY Employment Support Fund", column => column.Company, "Web Payroll Company").RowExists();
       }
       
       [Test(Order = 12)]
       public void VerifyTypeAscendingSort()
       {
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.TypeFilter2, FilterType.Is, "LIT");
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(col => col.Type, "LIT", col => col.Company, "Deferred Compensation Company", col => col.State, "Alabama").RowExists();
       }
       
       [Test(Order = 13)]
       public void VerifyTypeDescendingSort()
       {
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.TypeFilter2, FilterType.Is, "SUI");
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(col => col.Type, "SUI", col => col.Code, "AKSUIEE").RowExists();
       }
       
       [Test(Order = 14)]
       public void VerifyIsEmployerTaxY()
       {
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.IsEmployerTaxFilter, FilterType.Is, "Y");
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(col => col.IsEmployerTax, "Y", col => col.Code, "AKSUIER").RowExists();
       }

       [Test(Order = 15)]
       public void VerifyIsEmployerTaxN()
       {
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.IsEmployerTaxFilter, FilterType.Is, "N");
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(col => col.IsEmployerTax, "N", col => col.Code, "AKSIT").RowExists();
       }

       [Test(Order = 16)]
       public void VerifyEmployerIDNumber()
       {
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.EmployerIDNumberFilter, FilterType.StartsWith, "QGA-87546-1");
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(col => col.EmployerIDNumber, "QGA-87546-1", col => col.Code, "GASIT").RowExists();
       }

       [Test(Order = 17)]
       public void VerifyW2Box14Label()
       {
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.W2Box14LabelFilter, FilterType.Is, "QUBOX14A");
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(col => col.W2Box14Label, "CHQ Box 14 a", col => col.Code, "GASUIER").RowExists();
       }

       [Test(Order = 18)]
       public void VerifyUseSystemRateY()
       {
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.UseSystemRateFilter, FilterType.Is, "Y");
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(col => col.UseSystemRate, "Y", col => col.Code, "AKSUIEE", col => col.Company, "Deferred Compensation Company").RowExists();
       }

       [Test(Order = 19)]
       public void VerifyUseSystemRateN()
       {
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.UseSystemRateFilter, FilterType.Is, "N");
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(col => col.UseSystemRate, "N", col => col.Code, "AKSUIEE", col => col.Company, "HUCO2-CalenHR - US Comp 2").RowExists();
       }

       [Test(Order = 20)]
       public void VerifyContributionRateFields()
       {
           // USE SYSTEM RATE = Y
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.CodeFilter, FilterType.Is, "MOUAFER");
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(col => col.Code, "MOUAFER", col => col.Company, "Chequemates US 4", col => col.UseSystemRate, "Y", col => col.CRateCurrent, "0.0000 %", col => col.CRateFuture, "4.4444 %", col => col.CRateFutureEffectiveDate, "01/01/2025").RowExists();

           // USE SYSTEM RATE = N & CONT RATE > 0
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.CodeFilter, FilterType.Is, "OHSUIER");
           UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(col => col.Code, "OHSUIER", col => col.Company, "Chequemates US 4", col => col.UseSystemRate, "N", col => col.CRateCurrent, "0.2000 %", col => col.CRateFuture, "0.2200 %", col => col.CRateFutureEffectiveDate, "01/01/2029").RowExists();
       }
       #endregion SUMMARY PAGE
    }
}
